package listfactory;

import factory.Item;
import factory.Page;

import java.util.Iterator;

public class ListPage extends Page {
    public ListPage(String title, String author) {
        super(title, author);
    }

    @Override
    public String makeHtml() {
        StringBuilder builder = new StringBuilder();
        builder.append("<html>\n");
        builder.append("<head>\n");
        builder.append("<meta charset=\"UTF-8\">\n");
        builder.append("<title>").append(title).append("</title>\n");
        builder.append("</head>\n");

        builder.append("<body>\n");
        builder.append("<h1>").append(title).append("</h1>");
        builder.append("<ul>\n");
        Iterator<Item> iterator = context.iterator();
        while(iterator.hasNext()){
            Item item = iterator.next();
            builder.append(item.makeHtml());
        }
        builder.append("</ul>\n");
        builder.append("<hr>").append("<address>").append(author).append("</address>\n");
        builder.append("</body>\n");
        builder.append("</html>\n");
        return builder.toString();
    }
}
